package com.inmerwebapp.services;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

@ManagedBean
public class AddMarkersView implements Serializable {
     
    /**
	 * 
	 */
	private static final long serialVersionUID = 8761732301603811220L;

	private MapModel emptyModel;

    private double lat;
      
    private double lng;
      
    public MapModel getEmptyModel() {
        return emptyModel;
    }
    
    public MapModel getLatLngModel(double lat, double lng) {
    	emptyModel = new DefaultMapModel();
        Marker marker = new Marker(new LatLng(lat, lng));
        emptyModel.addOverlay(marker);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Added", "Lat:" + lat + ", Lng:" + lng));
        return emptyModel;
    }    
  
    public double getLat() {
        return lat;
    }
  
    public void setLat(double lat) {
        this.lat = lat;
    }
  
    public double getLng() {
        return lng;
    }
  
    public void setLng(double lng) {
        this.lng = lng;
    }
      
    public void addMarker() {
    	if( emptyModel == null){
            emptyModel = new DefaultMapModel();
    	}
        Marker marker = new Marker(new LatLng(lat, lng));
        emptyModel.addOverlay(marker);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Added", "Lat:" + lat + ", Lng:" + lng));
    }
}